package cn.virens.web.common;

import org.springframework.ui.Model;

/**
 * 通用控制器-JSON
 * 
 * @文件   :BaseJqGridController.java
 * @作者   :cn.loioi
 * @创建时间 :2016年10月13日 下午1:10:43
 */
public class BaseJSONController extends BaseController {

	protected BaseJSONController() {
		super();
	}

	/**
	 * @param baseTemplateUrl 模板根路径
	 */
	protected BaseJSONController(String baseTemplateUrl) {
		super(baseTemplateUrl);
	}

	protected final Model renderSuccess(Object data, Model model, String msg) {
		model.addAttribute("data", data);
		model.addAttribute("success", true);
		model.addAttribute("message", msg);
		return model;
	}

	protected final Model renderSuccess(Model model, String msg) {
		model.addAttribute("success", true);
		model.addAttribute("message", msg);
		return model;
	}

	protected final Model renderSuccess(Object data, Model model) {
		model.addAttribute("data", data);
		model.addAttribute("success", true);
		return model;
	}

	protected final Model renderSuccess(Model model) {
		model.addAttribute("success", true);
		return model;
	}

	protected final Model renderFail(Model model, String code, String msg) {
		model.addAttribute("success", false);
		model.addAttribute("message", msg);
		model.addAttribute("code", code);
		return model;
	}

	protected final Model renderFail(Model model, String msg) {
		model.addAttribute("success", false);
		model.addAttribute("message", msg);
		return model;
	}

	protected final Model renderFail(Model model) {
		model.addAttribute("success", false);
		return model;
	}
}
